SETUPLEN    equ 4
BOOTSEG     equ 0x07c0
INITSEG     equ 0x9000
SETUPSEG    equ 0x9020
SYSSEG      equ 0x1000

start:
    mov ax, BOOTSEG
    mov ds, ax
    mov ax, INITSEG
    mov es, ax
    mov cx, 256
    sub si, si
    sub di, di
    rep
    movsw           ; 将bootsect.s从0x7c00移动到0x90000
    jmp INITSEG:go
go: mov ax, cs
    mov ds, ax
    mov es, ax
    mov ss, ax
    mov sp, 0xff00

load_setup:
    mov dx, 0x00
    mov cx, 0x02
    mov bx, 0x0200
    mov ax, 0x0200 + SETUPLEN
    int 0x13        ; 加载setup.s到0x90200
    jnc ok_load_setup
    mov dx, 0x00
    mov ax, 0x00
    int 0x13
    jmp load_setup  ; 加载失败则复位软盘，重新加载

ok_load_setup:
    mov ah, 0x03
    xor bh, bh
    int 0x10        ; 获取光标位置

    mov cx, 24
    mov bx, 0x0007
    mov bp, msg
    mov ax, 0x1301
    int 0x10        ; 打印字符串

load_system:
    mov ax, SYSSEG
    mov es, ax
    mov dx, 0x00
    mov cx, 0x06
    mov bx, 0x00
    mov ax, 0x0201
    int 0x13        ; 加载head.s到0x10000
    jnc ok_load_system
    mov dx, 0x00
    mov ax, 0x00
    int 0x13
    jmp load_system ; 加载失败则复位软盘，重新加载

ok_load_system:
    jmp SETUPSEG:0  ; 跳转到setup.s的内容

msg:
    db 13, 10
    db "Loading system ..."
    db 13, 10, 13, 10

    times 0x1fe - ($ - $$) db 0 ; 填写0，直到0x1fe
    dw 0xaa55       ; 启动盘标识
